"""
    dji_redis 客户端
"""
import json

import redis

class RedisClient:
    def __init__(self, host='192.168.70.229', port=6379, db=0):
        # 使用连接池
        # with open("../config/config.json") as f:
        #     config = json.load(f)
        #     self.host = config['redis']['host']
        #     self.port = config['redis']['port']
        #     self.db = config['redis']['db']

        self.pool = redis.ConnectionPool(host=host, port=port, db=db)
        self.client = redis.Redis(connection_pool=self.pool)

    def set(self, key, value):
        self.client.set(key, value)

    def get(self, key):
        return self.client.get(key)

    def lpush(self,key, value, limit):
        self.client.lpush(key, value)
        # 只保留100条信息
        self.client.ltrim(key, 0, limit)

    def get_list(self, key, start, limit):
        return self.client.lrange(key, start, start + limit - 1)